<?php
//要加密的数据
$data = [];
$data = array_pad($data,100,mt_rand(1,99999));

$data = http_build_query($data,'','&',PHP_QUERY_RFC3986);
//	echo '加密的数据：' . $data . "\r\n";
$encrypted = "";
//私钥加密后的数据
openssl_private_encrypt($data, $encrypted, openssl_get_privatekey($userPrivateKey, $userScript));
dd($encrypted);die;

//加密后的内容通常含有特殊字符，需要base64编码转换下
$encrypted = base64_encode($encrypted);
echo "私钥加密后的数据:" . $encrypted . "\r\n";

//公钥解密
openssl_public_decrypt(base64_decode($encrypted), $decrypted, openssl_get_publickey($userPublicKey['key']));
echo "公钥解密后的数据:" . $decrypted, "\r\n";



//----相反操作。公钥加密
openssl_public_encrypt($data, $encrypted, openssl_get_publickey($userPublicKey['key']));
$encrypted = base64_encode($encrypted);
echo "公钥加密后的数据:" . $encrypted . "\r\n";

openssl_private_decrypt(base64_decode($encrypted), $decrypted, openssl_get_privatekey($userPrivateKey, $userScript));//私钥解密
echo "私钥解密后的数据:" . $decrypted . "n";
